import {useRoute} from "vue-router"
import {watch, computed} from "vue"

/**
 * @param
 */
export function useRouteHook(params: { queryChange?: Function }) {
    const route = useRoute()

    const query = computed(() => {
        return route.query
    })

    watch(query, function (value) {
        if (typeof params.queryChange === 'function') {
            params.queryChange(value)
        }
    }, {
        immediate: true
    })

    return {
        query
    }
}